"""Audit log repository implementation (Synchronous)."""

from __future__ import annotations

from sqlalchemy.orm import Session

from ..models.audit_log import AuditLog
from .base import Repository
from ..schemas.audit_log import AuditLogCreate
from ..schemas.base import ORMBase


# Audit logs are read-only after creation, so no update schema
class DummyUpdate(ORMBase):
    """Dummy update schema for audit logs (not used)."""

    pass


class AuditLogRepository(Repository[AuditLog, AuditLogCreate, DummyUpdate]):
    """Repository for AuditLog operations (read-only after creation, Synchronous)."""

    def __init__(self, session: Session) -> None:
        super().__init__(AuditLog, session)

    def get_by_actor(self, actor_id: int, skip: int = 0, limit: int = 100) -> list[AuditLog]:
        """Get audit logs by actor with pagination."""
        return (
            self.session.query(AuditLog)
            .filter(AuditLog.actor_id == actor_id)
            .order_by(AuditLog.created_at.desc())
            .offset(skip)
            .limit(limit)
            .all()
        )

    def get_by_action(self, action: str, skip: int = 0, limit: int = 100) -> list[AuditLog]:
        """Get audit logs by action type with pagination."""
        return (
            self.session.query(AuditLog)
            .filter(AuditLog.action == action)
            .order_by(AuditLog.created_at.desc())
            .offset(skip)
            .limit(limit)
            .all()
        )

    def get_recent(self, limit: int = 50) -> list[AuditLog]:
        """Get recent audit logs."""
        return self.session.query(AuditLog).order_by(AuditLog.created_at.desc()).limit(limit).all()
